<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
    <!--<script src="https://code.jquery.com/jquery-3.0.0.min.js"></script>-->
</head>
<body>

<!--<script>
    //promise封装异步操作
    let p = new Promise((resolve, reject) => {
        // 1、异步操作
        $.ajax({
            url: "mock/user.json",
            success: function (data) {
                console.log("查询用户成功", data);
                resolve(data);
            },
            error: function (err) {
                reject(err);
            }
        });

        p.then((obj) => {
            return new Promise((resolve, reject) => {
                $.ajax({
                    url: `mock/user_course_${obj.id}.json`,
                    success: function (data) {
                        console.log("查询用户课程成功:", data);
                        resolve(data);
                    },
                    error: function (err) {
                        reject(err);
                    }
                });
            })
        }).then((data) => {
            console.log("上一步的结果:", data);
            $.ajax({
                url: `mock/course_score_${data.id}.json`,
                success: function (data) {
                    console.log("查询用户得分成功:", data);
                    resolve(data);
                },
                error: function (err) {

                }
            });
        })
    });
</script>-->

<script>
    function get(url, data) {
        return new Promise((resolve, reject) => {
            $.ajax({
                url: url,
                data: data,
                success: function (data) {
                    resolve(data);
                },
                error: function (err) {
                    reject(err);
                }
            })
        });
    }

    get("mock/user.json").then((data) => {
        console.log("用户查询成功了,", data);
        return get(`mock/user_course_${data.id}.json`);
    }).then((data) => {
        console.log("课程查询成功了", data);
        return get(`mock/course_score_${data.id}.json`);
    }).then((data) => {
        console.log("课程成绩查询成功了", data);
    }).catch((err) => {
        console.log("出现异常", err);
    });

</script>
</body>
</html>